package cn.zz.comm.exception.enums;

import cn.zz.comm.exception.BizErrorCode;
import lombok.Getter;

/**
 * @author zhongq
 * @since 2023/01/09
 */
@Getter
public enum SysErrorCode implements BizErrorCode {
	SUCCESS("ok"),
	I_AM_A_TEAPOT("i am a teapot!"),

	// record
	RECORD_EARLY_USE("record early use {}"),
	RECORD_IN_USE("record in use {}"),

	// sys
	HANDLER_NOT_FOUND("not found handler {}_{}"),

	NOT_LOGIN("you have not login, please login"),
	SIGNATURE_VALIDATION_FAILED("signature verification failed"),

	FILE_TOO_LARGE("uploaded file is too large"),

	BAD_REQUEST("bad request"),
	UNAUTHORIZED("unauthorized"),
	NOT_FOUND("not found"),
	TOO_MANY_REQUEST("too many requests"),

	SYSTEM_ERROR("internal server error"),
	BAD_GATEWAY("bad gateway"),
	SERVICE_UNAVAILABLE("service unavailable"),
	GATEWAY_TIMEOUT("gateway timeout"),

	DATABASE_ERROR("database error"),
	NETWORK_CONN_ERROR("network connection error"),
	JSON_EXCEPTION("JSON data parsing error"),

	// 400
	PARAM_INVALID("params are invalid, {}"),

	// 401
	USER_NOT_LOGIN("user has not logged in"),
	ADMIN_NOT_LOGIN("admin has not logged in"),

	// 403
	ACCOUNT_PASSWORD_ERROR("account password error"),

	ACCESS_TOO_OFTEN("user access too often on {}"),
	NO_ACCESS("user {} has no access to perform operation {}"),

	// 404

	USER_NOT_FOUND("uid {} not found"),
	RECORD_NOT_FOUND("record not found {}"),

	// 500
	FATAL_ERROR("a fatal error happened, details: {}");

	private final String pattern;

	SysErrorCode(String pattern) {
		this.pattern = pattern;
	}

	@Override
	public String code() {
		return name();
	}

	@Override
	public String pattern() {
		return pattern;
	}
}